<script type="text/javascript">
$(document).ready(function(){
	var id=$("input[name=id]").val();	   						   	
})
function delete_image(pindex)
	{		
		if(confirm("delete this image?"))
		{
			var id=$("input[name=id]").val();
			$.post('admin_product/delete_image',{
					'id' : id,
					'pindex':pindex			
			},function(data){
				$("div[name=dvimage"+pindex+"]").remove();
			})
		}
	}
</script>

<h3>Product Management [Add / Edit Form]</h3>
<div></div>
<form enctype="multipart/form-data" method="post" action="admin_product/save<?=$parameter;?>">
	<table class="tblist2">
		<tr>
			<th>Product Image</th>
			<td>
				<? 
					$visible = @$rs['product_image_1']!='' ? "block" : "none";
					$productimage = @explode('.',$rs['product_image_1']);				
					$productimage = @$productimage[0].'_140x140.'.@$productimage[1];
				?>
					<div name="dvimage1" style="display:<?=$visible;?>">
						<img src="product/<?=$productimage;?>">
						<input type="hidden" name="product_image_1" value="<?=@$rs['product_image_1'];?>">
						<input type="button" class="btn_delete" name="btndeleteimage" onclick="delete_image(1);" />						
					</div> 
				<input type="hidden" name="id" value="<?=@$rs['id'];?>" />
				<input type="hidden" name="create_date" value="<? if(@$rs['create_date']>0)echo @$rs['create_date'];else echo date("Y-m-d H:i:s");?>" />
				<input type="hidden" name="update_date" value="<? if(@$rs['update_date']>0)echo @$rs['update_date'];else echo date("Y-m-d H:i:s");?>" />
				<input type="hidden" name="status" value="1" />
				<input type="file" name="flproductimage_1" >
			</td>
		</tr>				
		<tr>
			<th width="150">Category</th>
			<td>
            	
            	<select name="cat_lv1">
            		<option value="">-- select category --</option>
            		<? foreach($cat_lv1 as $item):
					$selected = $item['id']==@$rs['cat_lv1'] ? 'selected="selected"' : "";
					echo '<option value="'.$item['id'].'" '.$selected.'>'.$item['name'].'</option>';
					endforeach;
					?>
            	</select>
            	<span class="txtOrange">*</span>
            &nbsp;</td>
		</tr>			
		<tr>
		  <th>Product Code</th>
		  <td><input name="product_code" type="text" id="product_code" value="<?=@$rs['product_code'];?>" size="80" /></td>
	  </tr>
		<tr>
			<th width="150">Product Name</th>
			<td>
            	<input name="name" type="text" value="<?=@$rs['name'];?>" size="80" /> <span class="txtOrange">*</span>
            </td>
		</tr>
		<tr>
			<th width="150">ขนาด</th>
			<td><input type="text" name="size" size="80" value="<?=@$rs['size'];?>">
            </td>
		</tr>
		<tr>
			<th width="150">Detail</th>
			<td><textarea name="detail" cols="80" rows="4"><?=@$rs['detail'];?></textarea>
            </td>
		</tr>		
		<tr>
			<th>Price ต่อหน่วย  </th>
			<td><input type="text" name="price" value="<?=@$rs['price'];?>"></td>
		</tr>
		<tr>
			<th>หน่วย (ราคา) </th>
			<td><input type="text" name="per_unit" value="<?=@$rs['per_unit'];?>"></td>
		</tr>
		<tr>
			<th>สินค้าใหม่ </th>
			<td><input type="checkbox" name="new_status" value="yes" <? if(@$rs['new_status']=='yes')echo 'checked="checked"';?>></td>
		</tr>
		<tr>
			<th>สินค้าขายดี </th>
			<td><input type="checkbox" name="hot_status" value="yes" <? if(@$rs['hot_status']=='yes')echo 'checked="checked"';?>></td>
		</tr>			
      </table>
      <table width="100%">
		<tr>
			<th width="150">Create Date</th>
			<td><?=@$rs['create_date'];?></td>
		</tr>
		<tr>
			<th width="150">Update Date</th>
			<td><?=@$rs['update_date'];?></td>
		</tr>
		<tr>			
			<td colspan="2" align="center">
				<input type="submit" value="Save" class=""> 
				<input type="button" value="  Back  " onclick="history.back();">				
			</td>
		</tr>
	</table>
</form>